#include "ustc_comdef.h"
#include "sys.h"

void k9f_init_gpio(void)
{
    //GPC14,CE  output
    SYS_OUTMASK_UINT32(IO_PCONC , 0x30000000, 0x10000000);
    SYS_OUTMASK_UINT16(IO_PUPC , 0x4000, 0x4000);//disable pull up resistor
    //GPG5, R/B, input
    //SYS_OUTMASK_CUST_U16(IO_PCONG , 0x0c00, 0x0000);
    //CUST_IO_OUTBM(IO_PUPG , 0x20, 0x20);//disable pull up resistor

    //GPC10, R/B, input
    SYS_OUTMASK_UINT32(IO_PCONC , 0x0300000, 0x0000);
    SYS_OUTMASK_UINT16(IO_PUPC , 0x400, 0x400);//disable pull up resistor
//    SETNCE;
}

extern int test_sd(void);
extern int test_camera(void);
extern int test_jpeg2bmp(UINT32 lp_jpeg_dec);
extern void test_enc(void);
extern void test_usb(void);

UINT32 disable_INT_S3C(UINT32 mask)
{
	UINT32 ret=*(unsigned long*)0x1E0000C;

	*(unsigned long*)0x1E0000C|=mask;

	return ret;
}

void enable_INT_S3C(UINT32 mask)
{
	*(UINT32*)0x1E0000C&=mask;
}

void s3c44bx_init()
{
	*(unsigned long*)0x01c00000 = 0x00000007;
	*(unsigned long*)0x01c00004 = 0xa0006000;
	*(unsigned long*)0x01c00008 = 0x00000000;
	*(unsigned long*)0x01c0000c = 0x00000000;

	*(unsigned long*)0x01c80000 = 0x15151002 ; //0x55111002 ; BWSCON
	*(unsigned long*)0x01c80004 = 0x00000600 ; //GCS0
	*(unsigned long*)0x01c80008 = 0x00007ffc ; //GCS1
	*(unsigned long*)0x01c8000c = 0x00007ffc ; //GCS2
	*(unsigned long*)0x01c80010 = 0x00007ffc ; //GCS3
	*(unsigned long*)0x01c80014 = 0x000005A0 ; //GCS4	; IOU
	//*(unsigned long*)0x01c80014 = 0x00007FFC ; GCS4	; IOU
	*(unsigned long*)0x01c80018 = 0x00007ffc ; //GCS5
	*(unsigned long*)0x01c8001c = 0x00018001 ; //0x0001ffff ; 0x0001002a ; 0x00018000 ; GCS6, EDO DRAM(Trcd=3, Tcas=2, Tcp=1, CAN=10bit)
	*(unsigned long*)0x01c80020 = 0x00018001 ; //0x0001002a ; 0x00018000 ; GCS7, EDO DRAM
	*(unsigned long*)0x01c80024 = 0x0086041a ; //0x008ff800 ; 0x0086041a ; Refresh(REFEN=1, TREFMD=0, Trp=3, Trc=5, Tchr=3)  953 

	//////////
	//;the original value is 0x7
	//*(unsigned long*)0x01c80028 = 0x00000007 ; Bank Size, 32MB/32MB
	*(unsigned long*)0x01c80028 = 0x00000006 ; //Bank Size, 8MB/8MB
	////////


	*(unsigned long*)0x01c8002c = 0x00000020 ; //MRSR 6(CL=2)
	*(unsigned long*)0x01c80030 = 0x00000020 ; //MRSR 7(CL=2)

	*(unsigned long*)0x01d80000 = 0x00038100 ;
	*(unsigned long*)0x01d80004 = 0x00007ff8 ;
	*(unsigned long*)0x01d80008 = 0x00000009 ;

	*(unsigned long*)0x01D30000 = 0x00000000 ;

	*(unsigned long*)0x01E00000 = 0x00000005 ; //enable IRQ
	*(unsigned long*)0x01E0000C = 0x03DFFFFF ; //enable EINT4 and global INT
	*(unsigned long*)0x01D20050 = 0x00010000 ; //High Leve mode of EINT4; bit[18:16]:000b low, 001b hig, 01xb falling, 10xb rising, 11xb both edge triggered
	*(unsigned long*)0x01D20040 = 0x00000300 ; //SET PGP4 to EINT4
	*(unsigned long*)0x01D20048 = 0x00000010 ; //disable PG4 Pull-up
}

